<?php
class RbacAction extends LoginAction
{
    public function index()
    {
        $this->display();
    }

    /**
     * 角色管理
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function role()
    {
        $RoleModel = M('Role');
        $roles = $RoleModel->select();
        $this->assign('roles', $roles);
        $this->display();
    }

    /**
     * 节点管理
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function node()
    {
        //获取节点
        $NodeModel = D('Node');
        $nodes = $NodeModel->getNodes(0, 1);
        $this->assign('nodes', $nodes);
        $this->display();
    }

    /**
     * 用户角色管理
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function user()
    {
        $UsersModel = D('Users');
        $data = $UsersModel->getUserList();
        $this->assign('page', $data['page']);
        $this->assign('users', $data['data']);
        $this->display();
    }

    /**
     * 角色权限管理
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function access()
    {
        $RoleModel = M('Role');
        $roles = $RoleModel->select();
        $this->assign('roles', $roles);
        $this->display();
    }

    /**
     * @param  $userId 用户标识
     * @return boolea
     * @author Ice <iceinto@mallog.com.cn>
     */
    protected function addRole($userId)
    {
        //新增用户自动加入相应权限组
        $RoleUser = M("RoleUser");
        $RoleUser->user_id = $userId;
        // 默认加入网站编辑组
        $RoleUser->role_id = 3;
        return $RoleUser->add();
    }
}

?>